package com.algo.pattern.command.command;

import com.algo.pattern.command.constants.RequestConstant;
import com.algo.pattern.command.request.CancelOrderRequest;
import com.algo.pattern.command.response.CancelOrderResponse;
import com.alibaba.fastjson.JSONObject;

/**
 * 取消订单请求命令
 */
public class CancelOrderRequestCommand extends AbstractMeituanRequestCommand<CancelOrderRequest, Boolean> {

    /**
     * 取消订单结果处理
     * @param response
     * @return
     */
    @Override
    protected Boolean handleResponse(String response) {
        if (response == null || "".equals(response)) {
            return false;
        }
        // 取消订单返回结果处理逻辑
        CancelOrderResponse cancelOrderResponse = JSONObject.parseObject(response, CancelOrderResponse.class);
        if("200".equals(cancelOrderResponse.getCode())) {
            return true;
        }
        return false;
    }

    /**
     * 请求路径
     * @return
     */
    @Override
    protected String getMethodName() {
        return RequestConstant.ORDER_CANCEL;
    }

}
